<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - function_objects.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2010  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_MR_FUNCTION_ObJECTS_Hh_
<font color='#0000FF'>#define</font> DLIB_MR_FUNCTION_ObJECTS_Hh_

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='function_objects_abstract.h.html'>function_objects_abstract.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../matrix.h.html'>../matrix.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../svm/sparse_vector.h.html'>../svm/sparse_vector.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>cmath<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>limits<font color='#5555FF'>&gt;</font>

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>struct</font> <b><a name='squared_euclidean_distance'></a>squared_euclidean_distance</b>
    <b>{</b>
        <b><a name='squared_euclidean_distance'></a>squared_euclidean_distance</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> : 
            lower<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
            upper<font face='Lucida Console'>(</font>std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font>::infinity<font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b><b>}</b>

        <b><a name='squared_euclidean_distance'></a>squared_euclidean_distance</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> l,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> u
        <font face='Lucida Console'>)</font> :
            lower<font face='Lucida Console'>(</font>l<font face='Lucida Console'>)</font>,
            upper<font face='Lucida Console'>(</font>u<font face='Lucida Console'>)</font>
        <b>{</b><b>}</b>

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> lower;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> upper;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> sample_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>double</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> sample_type<font color='#5555FF'>&amp;</font> a,
            <font color='#0000FF'>const</font> sample_type<font color='#5555FF'>&amp;</font> b
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b> 
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> len <font color='#5555FF'>=</font> <font color='#BB00BB'>length_squared</font><font face='Lucida Console'>(</font>a<font color='#5555FF'>-</font>b<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>lower <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> len <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> len <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> upper<font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> len;
            <font color='#0000FF'>else</font>
                <font color='#0000FF'>return</font> std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>struct</font> <b><a name='cosine_distance'></a>cosine_distance</b> 
    <b>{</b>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> sample_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>double</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> sample_type<font color='#5555FF'>&amp;</font> a,
            <font color='#0000FF'>const</font> sample_type<font color='#5555FF'>&amp;</font> b
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b> 
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> temp <font color='#5555FF'>=</font> <font color='#BB00BB'>length</font><font face='Lucida Console'>(</font>a<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#BB00BB'>length</font><font face='Lucida Console'>(</font>b<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>0</font>;
            <font color='#0000FF'>else</font>
                <font color='#0000FF'>return</font> <font color='#979000'>1</font><font color='#5555FF'>-</font><font color='#BB00BB'>dot</font><font face='Lucida Console'>(</font>a,b<font face='Lucida Console'>)</font><font color='#5555FF'>/</font>temp;
        <b>}</b>
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>struct</font> <b><a name='negative_dot_product_distance'></a>negative_dot_product_distance</b> 
    <b>{</b>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> sample_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>double</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> sample_type<font color='#5555FF'>&amp;</font> a,
            <font color='#0000FF'>const</font> sample_type<font color='#5555FF'>&amp;</font> b
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b> 
            <font color='#0000FF'>return</font> <font color='#5555FF'>-</font><font color='#BB00BB'>dot</font><font face='Lucida Console'>(</font>a,b<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>struct</font> <b><a name='use_weights_of_one'></a>use_weights_of_one</b> 
    <b>{</b>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> edge_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>double</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> edge_type<font color='#5555FF'>&amp;</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b> 
            <font color='#0000FF'>return</font> <font color='#979000'>1</font>;
        <b>}</b>
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>struct</font> <b><a name='use_gaussian_weights'></a>use_gaussian_weights</b> 
    <b>{</b>
        <b><a name='use_gaussian_weights'></a>use_gaussian_weights</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> 
        <b>{</b>
            gamma <font color='#5555FF'>=</font> <font color='#979000'>0.1</font>;
        <b>}</b>

        <b><a name='use_gaussian_weights'></a>use_gaussian_weights</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>double</u></font> g
        <font face='Lucida Console'>)</font>
        <b>{</b>
            gamma <font color='#5555FF'>=</font> g;
        <b>}</b>

        <font color='#0000FF'><u>double</u></font> gamma;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> edge_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>double</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> edge_type<font color='#5555FF'>&amp;</font> e
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b> 
            <font color='#0000FF'>return</font> std::<font color='#BB00BB'>exp</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font>gamma<font color='#5555FF'>*</font>e.<font color='#BB00BB'>distance</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_MR_FUNCTION_ObJECTS_Hh_
</font>


</pre></body></html>